const Koa = require('koa');

const route = require('koa-route'); //路由

const path= require('path');

const staticFile = require('koa-static'); //静态文件

const app = new Koa();

app.env = "development";
app.keys = ['app',]

app.use(async function (ctx, next) {
    console.log(">1");
    await next();
    const rt = ctx.response.get('X-Response-Time');
    console.log(`${ctx.method} ${ctx.protocol} ${ctx.url} - ${rt}`);
    console.log("1<");
});

app.use(staticFile(path.join(__dirname,'./static'))); //使用静态文件路由

const indexPage = async (ctx,next) => {
    console.log(">2");
    // await next();
    ctx.body = 'Hi';
    console.log("2<");
}
app.use(route.get('/', indexPage));

app.on('error', (err, ctx) => {
    console.error('server error', err, ctx);
});

app.listen(3000);